home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
ensoft11.zip
/
ENSOFT11.C
next >
Wrap
Text File
|
1986-01-01
|
3KB
|
140 lines
/************************************************************************/
/* Program in Small-C to convert a regular text file to Wordstar */
/* 'document' format with soft spaces and carriage returns. */
/* */
/* by Gordon Brandly, R.R.2, Fort Sask., AB, CANADA T8L 2N8 */
/* */
/* converted for use with Software Toolworks C/80 */
/* & added command line parameter passing */
/* - paul homchick 3/25/84 */
/* compiled for DOS using CI C86 */
/* - paul homchick 1/1/86 */
/************************************************************************/
#include "stdio.h"
#define VERSION "1.1C"
#define VDATE "1 Jan 86"
#define CR 0x0d
#define LF 0x0a
#define TAB 0x09
#define CPM_EOF 0x1a
#define TRUE 1
#define FALSE 0
#define ERROR -1
int startline, inword, inptr, outptr;
main(argc,argv)
int argc; char *argv[];
{
int c;
startline=TRUE;
inword=FALSE;
if(argc < 3)
{
printf("ensoft version %s %s\n",VERSION,VDATE);
printf("usage: ensoft ascii_input_name");
printf(" wordstar_output_name\n");
printf("converts text files to wordstar document format.\n");
exit(0);
}
if(strcmp(argv[1],argv[2])==0)
{
printf("Input and output filenames must differ.");
printf(" Aborting...\007\n");
exit(0);
}
if(!(inptr= fopen(argv[1],"r")))
{
printf("Can't open '%s'",argv[1]);
printf(" for input.\n");
exit(0);
}
if(!(outptr=fopen(argv[2],"wb")))
{
printf("Can't open '%s'",argv[2]);
printf(" for output. The disk directory is probably full.\n");
exit(0);
}
/************************************************************************/
/* main loop */
/************************************************************************/
printf("processing... ");
while ((c=getc(inptr))!=ERROR && c!=CPM_EOF)
putc(translate(c),outptr);
putc(CPM_EOF,outptr);
fclose(inptr);
fclose(outptr);
printf("done.\n");
}
/************************************************************************/
/* wordstar translation routine */
/************************************************************************/
translate(c)
int c;
{
if (c==LF)
{
if (startline)
{
putc(CR,outptr);
return(c); /* empty lines are 'hard' */
}
else
{
c=getc(inptr);
if ((c==' ') || (c==TAB)) /* lines beginning */
{ /* with a space or TAB probably */
/* begin a new paragraph */
putc(CR,outptr);
putc(LF,outptr);
}
else if ((c==LF) || (c==(-1)) || (c==CPM_EOF))
{
putc(CR,outptr); /* end of a paragraph? */
putc(LF,outptr);
startline=TRUE;
return(translate(c));
}
else
{
putc((CR | 0x80),outptr);
putc(LF,outptr);
}
startline=TRUE;
return(translate(c));
}
}
else if (c==' ')
{
if (inword)
{
inword=FALSE; /* we just finished a word, */
return(c); /* so this is a 'hard' space */
}
if (startline)
return(c); /* spaces at the beginning of */
/* a line are also 'hard' spaces */
return(c | 0x80); /* otherwise, a 'soft' space */
}
else if (c==(-1)||c==CPM_EOF)
{
return(CPM_EOF);
}
else
{
inword=TRUE; /* any other character counts as */
startline=FALSE; /* a word. */
return(c);
}
}